//
//  NewFriendTableViewCell.m
//  YMIM
//
//  Created by admin on 2022/3/24.
//

#import "NewFriendTableViewCell.h"
#import <Masonry/Masonry.h>
#import <SDWebImage/SDWebImage.h>
#import <MJExtension/MJExtension.h>
@implementation NewFriendTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
     
        [self initview];
    }
    
    return self;
}
-(void)setApplyInfo:(YMFriendApplyInfo *)applyInfo{
    
    
    if (applyInfo.applyState ==2) {
        
        [self.statusButton setTitle:@"已添加" forState:UIControlStateNormal];
        self.statusButton.hidden = NO;
        self.agreeButton.hidden = YES;
        self.refuseButton.hidden = YES;
        
    }else if (applyInfo.applyState == 3){
        
        [self.statusButton setTitle:@"已拒绝" forState:UIControlStateNormal];
        self.statusButton.hidden = YES;
        self.agreeButton.hidden = NO;
        self.refuseButton.hidden = NO;
    }
    self.nameLable.text = applyInfo.applyUserName;
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:applyInfo.applyUserAvatar]];
    if (applyInfo.applyMessage == nil ||[applyInfo.applyMessage isEqualToString:@""]) {
        
        self.infoLable.text = [NSString stringWithFormat:@"申请信息：%@",@"无"];
    }else{
        
        self.infoLable.text = [NSString stringWithFormat:@"申请信息：%@",applyInfo.applyMessage];
    }
    
        
}
    
-(void)initview{
    
    [self.contentView addSubview:self.nameLable];
    [self.contentView addSubview:self.infoLable];
    [self.contentView addSubview:self.headImageView];
    [self.contentView addSubview:self.agreeButton];
    [self.contentView addSubview:self.refuseButton];
    [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.left.mas_lessThanOrEqualTo(self.contentView.mas_left).offset(10);
        make.size.mas_equalTo(CGSizeMake(45, 45));
    }];
    [self.nameLable mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.headImageView.mas_right).offset(10);
        make.top.mas_equalTo(self.headImageView.mas_top).offset(1);
        
    }];
    
    [self.infoLable mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.nameLable.mas_left);
        make.bottom.mas_equalTo(self.headImageView.mas_bottom).offset(-1);
        
    }];
    
    [self.refuseButton mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.right.mas_lessThanOrEqualTo(self.contentView.mas_right).offset(-20);
        make.size.mas_equalTo(CGSizeMake(60, 30));
    }];
    
    [self.agreeButton mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.right.mas_lessThanOrEqualTo(self.refuseButton.mas_left).offset(-20);
        make.size.mas_equalTo(CGSizeMake(60, 30));
    }];
    
    [self.contentView addSubview:self.statusButton];
    [self.statusButton mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.right.mas_lessThanOrEqualTo(self.contentView.mas_right).offset(-20);
        make.size.mas_equalTo(CGSizeMake(60, 30));
        
    }];
    
    self.statusButton.hidden = YES;
    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
-(UIImageView *)headImageView{
    
    if (_headImageView == nil) {
        
        _headImageView = [[UIImageView alloc]init];
//        _headImageView.backgroundColor = [UIColor orangeColor];
        _headImageView.layer.cornerRadius = 22.5;
        _headImageView.clipsToBounds = YES;
    }
    
    return _headImageView;
}
-(UILabel *)infoLable{
    
    if (_infoLable == nil) {
    
        _infoLable = [[UILabel alloc]init];
        _infoLable.text = @"申请信息:";
        _infoLable.textColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1];
        _infoLable.font = [UIFont systemFontOfSize:14];
    }
    return _infoLable;
}
-(UILabel *)nameLable{
    
    if (_nameLable == nil) {
    
        _nameLable = [[UILabel alloc]init];
        _nameLable.text = @"我是昵称";
        _nameLable.textColor = [UIColor blackColor];
        _nameLable.font = [UIFont systemFontOfSize:16];
    }
    return _nameLable;
}
-(UIButton *)refuseButton{
    
    if (_refuseButton== nil) {
        
        _refuseButton = [[UIButton alloc]init];
         [_refuseButton setTitle:@"拒绝" forState:UIControlStateNormal];
        [_refuseButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _refuseButton.titleLabel.font = [UIFont systemFontOfSize:15];
        _refuseButton.layer.cornerRadius = 5;
        _refuseButton.layer.masksToBounds = YES;
        _refuseButton.backgroundColor = [UIColor colorWithRed:72/255.0 green:142/255.0 blue:255/255.0 alpha:1];
    }
    return _refuseButton;
}
-(UIButton *)statusButton{
    
    if (_statusButton== nil) {
        
        _statusButton = [[UIButton alloc]init];
        [_statusButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _statusButton.titleLabel.font = [UIFont systemFontOfSize:15];
        _statusButton.layer.cornerRadius = 5;
        _statusButton.layer.masksToBounds = YES;
        _statusButton.backgroundColor = [UIColor grayColor];
    }
    return _statusButton;
}

-(UIButton *)agreeButton{
    
    if (_agreeButton == nil) {
        
        _agreeButton = [[UIButton alloc]init];
         [_agreeButton setTitle:@"同意" forState:UIControlStateNormal];
        [_agreeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _agreeButton.titleLabel.font = [UIFont systemFontOfSize:15];
        _agreeButton.layer.cornerRadius = 5;
        _agreeButton.layer.masksToBounds = YES;//101 222 121
        _agreeButton.backgroundColor = [UIColor colorWithRed:101/255.0 green:222/255.0 blue:121/255.0 alpha:1];
    }
    return _agreeButton;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
